package com.stream;

import java.util.Scanner;

/**
 * @author weijingchen
 * @DateTime 2025-06-16
 */
public class Test03 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        User user = new User();
        while (true) {
            try {
                System.out.println("请输入姓名");
                String name = sc.nextLine();
                user.setName(name);
                System.out.println("请输入年龄");
                String ageStr = sc.nextLine();
                int age = Integer.parseInt(ageStr);

                user.setAge(age);
                System.out.println(user);
                break;
            } catch (NumberFormatException e) {
                System.out.println("年龄输入错误");
            } catch (Exception e) {
                System.out.println("姓名、年龄输入错误");
            }
        }
    }
}
